<?php

import("data.db.DbAbstractTable");
import("data.db.DbFactory");
		
class DbPageInfo extends DbAbstractTable {
	
	public $className = "data.logic.content.PageInfo";
	const CLASS_NAME =  "data.logic.content.PageInfo";
	
	//
	// SQL Table description section
	//
	const TB_TABLENAME	= "pd_page_info";
	const TB_I			= 'pgi';
	
	const TB_TITLE		= 'pgi_title';
	const TB_KEYWORDS	= 'pgi_keywords';
	const TB_DESCRIPTION = 'pgi_description';
	const TB_LOCALE	= 'pgi_locale';
	
	public static function _get_TABLENAME() {return self::TB_TABLENAME;}
	public static function _get_ID() {return self::TB_I."_id";}
	public static function _get_SUFFIX() {return self::TB_I;}
	//
	//
	function forwardForeignCollection() {
		return array("Node"=>"data.logic.catalogue.Node");
	}
	
	// properties
	public $title;
	public $keywords;
	public $description;
	public $locale;
	
	function __construct($noinit=false) {
		parent::__construct($noinit);
	}
	
	function getTitle() {
		return $this->title;
	}
	function setTitle($value) {
		$this->title = $value;
	}
	
	function getKeywords() {
		return $this->keywords;
	}
	function setKeywords($value) {
		$this->keywords = $value;
	}
	
	function getDescription() {
		return $this->description;
	}
	function setDescription($value) {
		$this->description = $value;
	}
	
	function setCategory(&$cat) {
		$this->forwardForeigns["Node"]->setForeign($cat);
	}
	function &getCategory() {
		return $this->forwardForeigns["Node"]->getForeign();
	}
	
	// restore
	function fillEntity($arrResult) {
		parent::fillEntity($arrResult);
		$this->setTitle($arrResult[self::TB_TITLE]);
		$this->setKeywords($arrResult[self::TB_KEYWORDS]);
		$this->setDescription($arrResult[self::TB_DESCRIPTION]);
		$this->setLocale(DbFactory::getLocale($arrResult[self::TB_LOCALE]));
	}
	
	//store
	function fillFields() {
		parent::fillFields();
		$this->fildsForStore[self::TB_TITLE] = "'".$this->getTitle()."'";
		$this->fildsForStore[self::TB_KEYWORDS] = "'".$this->getKeywords()."'";
		$this->fildsForStore[self::TB_DESCRIPTION] = "'".$this->getDescription()."'";
		$this->fildsForStore[self::TB_LOCALE] = "'".$this->locale->getId()."'";
	}
	
	//static
	function findByCategoryIdAndLang($categoryId, $langId) {
		return parent::__selectByCriteria(
			self::TB_LOCALE."='".$langId."' and ".
			DbAbstractTable::_get_FOREIGN(self::CLASS_NAME, "data.logic.catalogue.Node")."='$categoryId'",
			self::CLASS_NAME);
	}
	
	// same for all classes
	public static function findAll() {return parent::findAll(self::CLASS_NAME);}
    public static function findById($id) {return parent::findById($id, self::CLASS_NAME);}
}
?>